import 'entity_factory.dart';

class Default<T> {
  int? status;
  String? message;
  T? data;
  ///当有分页信息时，把total放在最外层方便使用，可以根据自己需要进行调整
  int? total;

  Default({this.status, this.message});

  Default.fromJson(dynamic json) {
    status = json["code"];
    message = json["message"];
    if (T == null) {
      return;
    }
    if (T.toString() == "String") {
      if (json['data'] is String) data = json['data'];
    } else if (T.toString() == "bool") {
      data = json['data'];
    } else {
      //当json包含分页信息时
      if (json['data'] is Map && json['data']['current_page'] != null && json['data']['total'] != null) {
        //获取分页中得total
        total = json['data']['total'];
        data = EntityFactory.generateOBJ<T>(json['data']['data']);
      } else {
        data = EntityFactory.generateOBJ<T>(json['data']);
      }
    }
  }
}
